home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / pj-gs.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1993-04-16  |  7KB  |  291 lines

  1. #!/bin/sh
  2. # $Source: /hpux/shared/supp/usr/src/cmd/lp/model/PCL1,v $
  3. # $Revision: 70.2 $
  4.  
  5. # PaintJet driver for Ghostscript,
  6. # created by Philippe-Andre Prindeville <philipp@res.enst.fr>
  7.  
  8. # PCL level 1 interface
  9. #
  10. #=======================================================================#
  11. # OPTIONS RECOGNIZED: ( all may be preceded with a "-" )        #
  12. #    NOTE: Options marked with a "*" before their descriptions    #
  13. #          are provided for backward compatibility with the        #
  14. #          former hp2225a, hp2227a and hp3630a printer models -    #
  15. #           these models have become links to this model. Consult    #
  16. #          your printer reference manual to determine which        #
  17. #          options are valid for your particular printer.        #
  18. #                                    #
  19. # Horizontal Pitch Selection:                        #
  20. #    c          compressed print mode                #
  21. #    e            * expanded print pitch                #
  22. #    10           * 10 cpi (Pica print pitch)            #
  23. #              (expanded compressed on thinkjet and quietjet)#
  24. #    12           * 12 cpi (Elite print pitch)            #
  25. #                                    #
  26. # Print Quality Selection                        #
  27. #    q | lq           * near letter quality                #
  28. #                                    #
  29. # Font Selection                            #
  30. #    b | bold      * set font stroke weight to bold            #
  31. #                                    #
  32. # Output filtering: (Default Cooked)                    #
  33. #    r | raw        raw mode for plotting mode etc.            #
  34. #                                    #
  35. # Other:                                #
  36. #       nb        do not output banner page (to save paper)    #
  37. #                                    #
  38. #        NOTE: * = NOT OFFICIAL PCL LEVEL 1 OPTIONS, USE OF    #
  39. #              THESE OPTIONS MAY OR MAY NOT PRODUCE        #
  40. #              DESIRED RESULTS.                #
  41. #=======================================================================# 
  42.  
  43. PATH="/bin:/usr/bin:/usr/lib:/usr/local/bin"
  44. export PATH
  45.  
  46. # set up redirection of stderr
  47. log=/usr/spool/lp/log
  48. exec 2>>$log
  49.  
  50. # sec_class=`getconf SECURITY_CLASS`
  51. sec_class=
  52. if [ $? -ne 0 ]
  53. then
  54.         echo "getconf SECURITY_CLASS failed"
  55. fi
  56.  
  57. # Save the arguments to the model
  58. printer=`basename $0`
  59.  
  60. if [ "$sec_class" = "2" ]       # B1 Trusted System
  61. then
  62.     reqid=$1
  63.     user=$2
  64.     dev=$3
  65.     title=$4
  66.     copies=$5
  67.     options=$6
  68. else
  69.     reqid=$1
  70.     user=$2
  71.     title=$3
  72.     copies=$4
  73.     options=$5
  74. fi
  75.  
  76.  
  77. # Definitions of functions used within this script
  78. do_banner()
  79. {
  80.     # Print the standard header
  81.     x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  82.     echo "$x\n$x\n$x\n$x\n"
  83.     banner `echo $user`
  84.     echo "\n"
  85.     user=`pwget -n $user | line | cut -d: -f5`
  86.     if [ -n "$user" ]
  87.     then
  88.         echo "User: $user\n"
  89.     else
  90.         echo "\n"
  91.     fi
  92.     echo "Request id: $reqid    Printer: `basename $0`\n"
  93.     date
  94.     echo "\n"
  95.     if [ -n "$title" ]
  96.     then
  97.         banner "$title" 
  98.     fi
  99.     echo "\014\r\c"
  100. }
  101.  
  102. # Set up interface
  103. if [ -t 1 ]
  104. then
  105.     stty 9600 opost onlcr -parenb cs8 ixon -istrip clocal tab3 <&1 2>/dev/null
  106. else
  107.     slp -n -k 2>/dev/null
  108. fi
  109.  
  110. # Handle disable and cancel traps.
  111. trap "echo 'Terminated: $reqid'  >> $log; trap 15; kill -15 0; exit 0 " 15
  112.  
  113. # Set up printer default modes
  114. echo "\033&k0S\c"        # reset pitches
  115. echo "\033(s0B\033)s0B\c"    # reset stroke weights
  116. echo "\033&d@\c"        # disable auto-underline
  117. echo "\033&l6D\c"        # reset to 6 lpi
  118. echo "\033(s0Q\c"        # reset print quality
  119. echo "\033&v0S\c"        # reset color
  120. echo "\033&k2G\c"        # Set line termination mode
  121.  
  122.  
  123. # Determine which options have been invoked
  124. pitch="def"
  125. weight="def"
  126. quality="def"
  127. # outputmode="cooked"
  128. outputmode="raw"
  129. # banner="yes"
  130. banner=
  131.  
  132. for i in $options
  133. do
  134.     case "$i" in
  135.     -c | c)   # compressed print
  136.         pitch="c";;
  137.  
  138.     -e | e)   # expanded print
  139.         pitch="e";;
  140.  
  141.     -10 | 10) # pitch set to 10 cpi
  142.         pitch="10";;
  143.  
  144.     -12 | 12) # pitch set to 12 cpi
  145.         pitch="12";;
  146.  
  147.     -q | q | -lq | lq) # near letter quality
  148.         quality=1;;
  149.  
  150.     -b | b | -bold | bold) # set font weight to bold
  151.         weight=1;;
  152.  
  153.     r | raw) # raw mode for binary output to printer
  154.         outputmode="raw";;
  155.  
  156.     -nb | nb) # do not output banner page
  157.         banner="";;
  158.  
  159.     esac
  160. done
  161.  
  162. shift; shift; shift; shift; shift
  163.  
  164. if [ "$sec_class" = "2" ]       # B1 Trusted System
  165. then
  166.     shift
  167.     files="$*"
  168.     Nofilter= Nolabel=
  169.     set -- `getopt fl $options`
  170.     if [ $? != 0 ]
  171.     then
  172.         exit 2
  173.     fi
  174.  
  175.     for opt in $*
  176.     do
  177.         shift
  178.         case $opt in
  179.           -f) Nofilter=$opt ;;
  180.           -l) Nolabel=$opt ;;
  181.           --) break ;;
  182.         esac
  183.     done
  184.  
  185.     # Print the sensitivity label of the process
  186.     echo "$x\n$x\n"
  187.     /usr/lib/lpbanner -j $reqid -t "$title" -u $user -p PCL1 -n $printer -d $dev $files
  188.     echo "\n$x\n$x"
  189.  
  190. else
  191.     # Assume that the rest of the arguments are files
  192.     files="$*"
  193.     # print the banner if nb option not specified
  194.     if [ -n "$banner" ]
  195.     then
  196.         do_banner
  197.     fi
  198. fi
  199.  
  200. # Print the spooled files
  201. i=1
  202. while [ $i -le $copies ]
  203. do
  204.         for file in $files
  205.         do
  206.  
  207.             # If raw mode, turn off output processing,
  208.             # set for no tab expansion
  209.             # If cooked mode, uncomment the cooked case if it is 
  210.             # desired not to print on the page perforations
  211.             case "$outputmode" in
  212.                 raw)    if [ -t 1 ]
  213.                     then
  214.                         stty raw 9600 -opost -parenb cs8 ixon -istrip clocal tab0 <&1 2>/dev/null
  215.                     else
  216.                         slp -r 2>/dev/null
  217.                     fi
  218.                     echo "\033&k0G";;        # Reset line termination mode
  219.             #    cooked)    echo "\033&l1L\r\c";;
  220.             esac
  221.  
  222.             case "$pitch" in
  223.                 def);;
  224.                 c)    echo "\033&k2S\r\c";;
  225.                 e)    echo "\033&k1S\r\c";;
  226.                 10)    echo "\033&k3S\r\c";;
  227.                 12)    echo "\033&k0S\r\c"
  228.                     echo "\033&k4S\r\c";;
  229.             esac
  230.  
  231.             case "$quality" in
  232.                 def);;
  233.                 *)    echo "\033(s${quality}Q\r\c";;
  234.             esac
  235.  
  236.             case "$weight" in
  237.                 def)    echo "\033(s0B\033)s0B\r\c";;
  238.                 *)    echo "\033(s${weight}B\r\c";;
  239.             esac
  240.  
  241.             if [ "$sec_class" = "2" ]    # B1 Trusted System
  242.             then
  243.                 /usr/lib/lprcat $Nofilter $Nolabel $file PCL1 $user $dev
  244.             else
  245.                 type=`file $file | sed 's/^[^:]*..//'`
  246.                 case "$type" in
  247.                 postscript*)
  248. #
  249. # We could do the following, but this would leave gs with a rather large
  250. # image in memory for (possibly) several minutes.  Better to use and
  251. # intermediate file, since cat is "lightweight"...
  252. #
  253. #                    gs -q -sDEVICE=paintjet -r180 -sOutputFile=- -dDISKFONTS -dNOPAUSE - < $file 2>/tmp/sh$$
  254.  
  255.                     gs -q -sDEVICE=paintjet -r180 -sOutputFile=/tmp/pj$$ -dDISKFONTS -dNOPAUSE - < $file 1>2
  256.                     cat /tmp/pj$$
  257.                     rm /tmp/pj$$
  258.                     needff=
  259.                     ;;
  260.                 *)    cat "$file" 2>/tmp/sh$$
  261.                     needff=1
  262.                     ;;
  263.                 esac
  264.  
  265.                 if [ -s /tmp/sh$$ ]
  266.                 then
  267. #                    cat /tmp/sh$$    # output any errors
  268.                     cat /tmp/sh$$ 1>2    # output any errors
  269.                 fi
  270.                 rm -f /tmp/sh$$
  271.                 if [ $needff ]; then echo "\014\r\c"; fi
  272.             fi
  273.  
  274.             echo "\033&k0S\r\c"        # reset pitches
  275.             echo "\033(s0B\033)s0B\r\c"    # reset stroke weights
  276.             echo "\033&d@\r\c"        # disable auto-underline
  277.             echo "\033&l6D\r\c"        # reset to 6 lpi
  278.             echo "\033(s0Q\c"        # reset print quality
  279.             echo "\033&v0S\c"        # reset color
  280.         done
  281.         i=`expr $i + 1`
  282.     done
  283.  
  284. # Insure all buffers are flushed to printer
  285. if [ -t 1 ]
  286. then
  287.     stty 9600 opost onlcr -parenb cs8 ixon -istrip clocal tab3 <&1 2>/dev/null
  288. fi
  289.  
  290. exit 0
  291.